package net.kleinhenz.norabase.client;

import com.smartgwt.client.widgets.Window;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.form.FilterBuilder;
import com.smartgwt.client.widgets.layout.VLayout;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.Button;
import com.smartgwt.client.types.VerticalAlignment;
import com.smartgwt.client.types.Alignment;

public class AdvancedFilterDialog extends Window {
	
	public AdvancedFilterDialog(final ListGrid grid) {

		setWidth("500px");
		setIsModal(false);
		setShowBody(true);
		setShowFooter(false);
		setShowHeaderBackground(false);
		setShowHeaderIcon(false);
		setShowMinimizeButton(false);
		setShowStatusBar(true);
		setShowTitle(true);
		centerInPage();
		setTitle("Advanced Rune Filter");
        setAutoSize(true);  
        setCanDragReposition(true);  
        setCanDragResize(true);  
        setMembersMargin(10);
        
        VLayout layout = new VLayout(10);
        layout.setWidth("100%");
        layout.setMargin(10);
        
        final FilterBuilder filterBuilder = new FilterBuilder();  
        filterBuilder.setDataSource(grid.getDataSource());  
        layout.addMember(filterBuilder);
        
        HLayout btnLayout = new HLayout(10);
        btnLayout.setAlign(Alignment.RIGHT);
        btnLayout.setDefaultLayoutAlign(VerticalAlignment.CENTER);
        btnLayout.setMembersMargin(10);
        
        Button btnSave = new Button("Filter");
        btnSave.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				grid.setCriteria(filterBuilder.getCriteria());
				AdvancedFilterDialog.this.destroy();
			}
		});
        btnLayout.addMember(btnSave);
        
        Button btnCancel = new Button("Cancel");
        btnCancel.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				AdvancedFilterDialog.this.destroy();
			}
		});
        btnLayout.addMember(btnCancel);

        layout.addMember(btnLayout);
        addItem(layout);
	}
}
